package com.ruoyi.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.TCommonFileUrl;
import com.ruoyi.system.service.ITCommonFileUrlService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * 文件链接Controller
 * 
 * @author ruoyi
 * @date 2023-12-08
 */
@RestController
@RequestMapping("/system/file")
public class TCommonFileUrlController extends BaseController
{
    @Autowired
    private ITCommonFileUrlService tCommonFileUrlService;

    private static Logger logger = LoggerFactory.getLogger(TCommonFileUrlController.class);
    /**
     * 查询文件链接列表
     */
    @PreAuthorize("@ss.hasPermi('system:file:list')")
    @GetMapping("/list")
    public TableDataInfo list(TCommonFileUrl tCommonFileUrl)
    {
        startPage();
        List<TCommonFileUrl> list = tCommonFileUrlService.selectTCommonFileUrlList(tCommonFileUrl);
        return getDataTable(list);
    }

    @GetMapping("/listExt")
    public AjaxResult listExt(TCommonFileUrl tCommonFileUrl)
    {
        //logger.debug("MMM listExt " + "listExt = " + tCommonFileUrl);
        //List<TCommonFileUrl> list = tCommonFileUrlService.selectTCommonFileUrlList(tCommonFileUrl);
        //return getDataTable(list);
        return success(tCommonFileUrlService.selectTCommonFileUrlList(tCommonFileUrl));
    }

    /**
     * 导出文件链接列表
     */
    @PreAuthorize("@ss.hasPermi('system:file:export')")
    @Log(title = "文件链接", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TCommonFileUrl tCommonFileUrl)
    {
        List<TCommonFileUrl> list = tCommonFileUrlService.selectTCommonFileUrlList(tCommonFileUrl);
        ExcelUtil<TCommonFileUrl> util = new ExcelUtil<TCommonFileUrl>(TCommonFileUrl.class);
        util.exportExcel(response, list, "文件链接数据");
    }

    /**
     * 获取文件链接详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:file:query')")
    @GetMapping(value = "/{fileId}")
    public AjaxResult getInfo(@PathVariable("fileId") Long fileId)
    {
        return success(tCommonFileUrlService.selectTCommonFileUrlByFileId(fileId));
    }

    /**
     * 新增文件链接
     */
    @PreAuthorize("@ss.hasPermi('system:file:add')")
    @Log(title = "文件链接", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TCommonFileUrl tCommonFileUrl)
    {
        tCommonFileUrl.setCreateBy(getNickName());
        return toAjax(tCommonFileUrlService.insertTCommonFileUrl(tCommonFileUrl));
    }

    /**
     * 修改文件链接
     */
    @PreAuthorize("@ss.hasPermi('system:file:edit')")
    @Log(title = "文件链接", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TCommonFileUrl tCommonFileUrl)
    {
        tCommonFileUrl.setUpdateBy(getNickName());
        return toAjax(tCommonFileUrlService.updateTCommonFileUrl(tCommonFileUrl));
    }

    /**
     * 删除文件链接
     */
    @PreAuthorize("@ss.hasPermi('system:file:remove')")
    @Log(title = "文件链接", businessType = BusinessType.DELETE)
	@DeleteMapping("/{fileIds}")
    public AjaxResult remove(@PathVariable Long[] fileIds)
    {
        return toAjax(tCommonFileUrlService.deleteTCommonFileUrlByFileIds(fileIds));
    }

    @Log(title = "文件链接", businessType = BusinessType.DELETE)
    @DeleteMapping("/removeExt")
    public AjaxResult removeExt(TCommonFileUrl tCommonFileUrl)
    {
        return toAjax(tCommonFileUrlService.deleteTCommonFileUrlByFileUrl(tCommonFileUrl.getFileUrl()));
    }

}
